<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
         :root,
        body {
            height: 100%;
            background: linear-gradient(to bottom, #797979, #1b1b1b);
        }
        
        a {
            text-decoration: none;
            color: black;
        }
        
        .c-nav {
            position: relative;
            width: 700px;
            height: 50px;
            background-color: white;
            margin: 50px auto;
            border-radius: 10px;
            box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.63);
            z-index: 1;
            overflow: hidden;
        }
        
        .c-nav ul li {
            float: left;
            height: 100%;
            width: 79px;
            font-weight: 700;
            text-align: center;
            line-height: 50px;
        }
        
        .c-nav .cloud {
            display: block;
            width: 79px;
            height: 50px;
            background-color: rgb(163, 163, 163);
            position: absolute;
            z-index: -1;
            border-radius: 8px;
        }
        
        .color {
            color: white;
        }
    </style>
    <script src="./82-animate.js"></script>
</head>

<body>
    <div id="c_nav" class="c-nav">
        <span class="cloud"></span>
        <ul>
            <li class="current"><a href="#">首页新闻</a></li>
            <li><a href="#">师资力量</a></li>
            <li><a href="#">活动策划</a></li>
            <li><a href="#">企业文化</a></li>
            <li><a href="#">招聘信息</a></li>
            <li><a href="#">公司简介</a></li>
            <li><a href="#">演示文本</a></li>
            <li><a href="#">演示文本</a></li>
        </ul>
    </div>
</body>
<script>
    // 1.获取元素
    var cloud = document.querySelector('.cloud');
    var c_nav = document.querySelector('.c-nav');
    var lis = c_nav.querySelectorAll('li');
    // 2.给所有的li绑定事件
    // 作为span的起始位置
    var current = 0;
    for (var i = 0; i < lis.length; i++) {
        // (1) 鼠标经过就把当前li的位置做为目标值
        lis[i].addEventListener('mouseenter', function() {
            animate(cloud, this.offsetLeft);
            for (var i = 0; i < a.length; i++) {
                a[i].style.color = 'black'
            }
        })

        // (2) 鼠标离开就回到起始位置
        lis[i].addEventListener('mouseleave', function() {
            animate(cloud, current);
        })

        // (3) 当鼠标点击 就把当前位置作为目标值
        lis[i].addEventListener('click', function() {
            current = this.offsetLeft;
        })
    }
</script>

</html>